package com.km.team.phsystem.service.impl;

import com.km.team.phsystem.beans.pojo.PhWindow;
import com.km.team.phsystem.beans.pojo.PhWindowExample;
import com.km.team.phsystem.beans.vo.PhWindowVo;
import com.km.team.phsystem.common.utils.StrUtils;
import com.km.team.phsystem.dao.mybatis.PhWindowMapper;
import com.km.team.phsystem.service.IPhWindowService;
import com.km.team.phsystem.service.impl.base.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("phService")
public class PhWindowServiceImpl extends BaseService<PhWindowServiceImpl, PhWindow> implements IPhWindowService {

    @Autowired
    PhWindowMapper mapper;

    @Override
    public int add(PhWindowVo vo) {
        PhWindow phWindow = new PhWindow();
        BeanUtils.copyProperties(vo, phWindow);
        phWindow.setPassword(StrUtils.getMD5(phWindow.getPassword()));
        //mapper.insert(phWindow);
        //新建窗口时默认状态为启用
        //phWindow.setStatus(Boolean.TRUE);
        return super.baseUpdate(phWindow);
    }

    @Override
    public List<PhWindow> getWindowList(PhWindowExample phWindowExample) {
        return mapper.selectByExample(phWindowExample);
    }


    @Override
    public int updateAccount(PhWindow phWindow) {
        phWindow.setUpdateTime(new Date());
        PhWindowExample phWindowExample = new PhWindowExample();
        phWindowExample.or().andIdEqualTo(phWindow.getId());
        if (phWindow.getPassword()!=null && !"".equals(phWindow.getPassword())){
            phWindow.setPassword(StrUtils.getMD5(phWindow.getPassword()));
        }
        return mapper.updateByExampleSelective(phWindow, phWindowExample);
    }

    @Override
    public int delete(PhWindowExample phWindowExample) {
        return mapper.deleteByExample(phWindowExample);
    }
}
